import json

import requests
url="https://chainid.network/page-data/sq/d/2609099887.json"
headers = {
        'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0'
    }
response = requests.get(url=url,headers=headers)

list_data=response.json()["data"]["allChain"]["nodes"]
# 设置最终存放清洗过的数据列表
data=[]
# 设置保留的关键词
str_list=["chain","chainId","name","explorers"]
# 遍历列表数据，进行清洗
for dict_data in list_data :
    # 数据清洗，保留需要的关键词
    dic_filter = {k: v for k, v in dict_data.items() if k in str_list}
    data.append(dic_filter)
# 将数据存放起来
json_data = json.dumps(data, indent=4)
with open('../data/chainID_data.json', 'w', encoding='utf-8') as f:
    f.write(json_data)

